<?php

namespace App\Exceptions;

use Exception;
use Symfony\Component\HttpKernel\Exception\HttpException;

class ApiException extends HttpException
{
    // 这里定义构造方法传入四个参数，分别是错误信息、默认异常码、错误信息的data数据，响应码
    public function __construct($message,$code = ExceptionCode::ERROR,$data =[],$statusCode=400){
        $this->data = $data;
        parent::__construct($statusCode,$message,null,[],$code);
    }

    // 允许业务错误时，自定义提示信息
    public function getData(){
        return $this->data;
    }
}
